package com.wgy.day15.String字符串类;



import java.util.Arrays;

public class Demo06StringConvert {
    /*String当中与转换相关的常用方法有:
    public char[] tocharArray(): 将当前字符串拆分成字符数组作为返回值.
    public byte[] getBytes():获得当前字符串底层的字节数组.
    public String replace(charSequence oldString,charSequence newString): 将所有出现的老字符串替换成为新的字符串,
    返回替换之后的结果新字符串.  charsequence 意思就是可以接收字符串类型*/

    public static void main(String[] args) {
        //转换成字符数组
        String str1 = "hello";
        char[] array1 = str1.toCharArray();
        System.out.println(array1[0]);      //h
        System.out.println(array1.length);  //5
        System.out.println("=====================");

        //转换成字节数组
        byte[] bytes = str1.getBytes();
        for (int i = 0; i < bytes.length; i++) {
            System.out.println(bytes[i]);

        }
        System.out.println("=======================");

        //字符串的内容替换
        String str2 = "How do you do?";
        String str3 = str2.replace("o", "*");
        System.out.println(str2);    //How do you do?
        System.out.println(str3);    //H*w d* y*u d*?
        String lang1 = "会不会玩啊,你大爷的!你大爷的!你大爷的!你大爷的!";
        String lang2 = lang1.replace("你大爷的", "****");
        System.out.println(lang1);   //会不会玩啊,你大爷的!你大爷的!你大爷的!你大爷的!
        System.out.println(lang2);   //会不会玩啊,****!****!****!****!


        char[] array2 = new char[]{'a', 'b', 'c'};
        System.out.println(array2);       //abc
        int[] array3 = new int[]{10, 20, 30};
        System.out.println(array3);       //[I@1b6d3586


    }


}
